#pragma once
#include <iostream>
#include <pthread.h>
#include <string>
#include <vector>

enum // 枚举
{
    DivZero=1,
    ModZero,
    UnKnow,
    Normal
};

static const std::string opers = "+-*/%";

class Task // 生产者生产的一个任务类
{
public:
    Task(char oper,int x, int y)
    :_oper(oper),_x(x),_y(y)
    {
    }

    std::string GainTask(int x, int y)const
    {
        std::string s;
        s += std::to_string(x);
        s += _oper;
        s += std::to_string(y);
        std::cout<<s<<std::endl;
        return s;
    }

    int CountTask(int x, int y)
    {
        switch (_oper)
        {
        case '+':
            return x + y;
            break;
        case '-':
            return x - y;
            break;
        case '*':
            return x * y;
            break;
        case '/':
        {
            if (x != 0)
                return x / y;
            else
                error = DivZero;
        }
        break;
        case '%':
        {
            if (x != 0)
                return x % y;
            else
                error = ModZero;
        }
        break;
        default:
            error = UnKnow;
        }
    }
    std::string ErrorToString()
    {
        std::string s;
        switch(error)
        {
            case 1:
            return  s = "DivZero";
            break;
            case 2:
            return s = "ModZero";
            break;
            case 3:
            return s = "UnKnow";
            break;
            default:
            return s = "Normal";
        }
    }
    void operator()()
    {
        std::cout<<GainTask(_x, _y)<<CountTask(_x,_y)<<ErrorToString()<<std::endl;
    }

private:
    int error =4;
    char _oper;
    int _x;
    int _y;
};
